const operateBtn = document.getElementById("operateBtn");
const columnBtn = document.getElementById("genColumnBtn");
const formBtn = document.getElementById("genFormBtn");

chrome.storage.local.get("selectState", (result) => {
  window.selectState = !!result.selectState;
  if (window.selectState) {
    operateBtn.innerText = "关闭插件";
    chrome.action.setIcon({
      path: "../images/icon48.png",
    });
  } else {
    operateBtn.innerText = "开启插件";
    chrome.action.setIcon({
      path: "../images/icon48_gray.png",
    });
  }
});

operateBtn.addEventListener("click", function () {
  tooglePluginStatus();
});

function tooglePluginStatus() {
  const result = (window.selectState = !window.selectState);
  chrome.storage.local.set({ selectState: result });
  if (result) {
    operateBtn.innerText = "关闭插件";
    chrome.action.setIcon({
      path: "../images/icon48.png",
    });
  } else {
    console.log('xxxxxxx',chrome.browserAction)
    operateBtn.innerText = "开启插件";
    chrome.action.setIcon({
      path: "../images/icon48_gray.png",
    });
  }
  chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
    chrome.tabs.sendMessage(tabs[0].id, {
      message: "tooglePluginStatus",
      data: { pluginState: result },
    });
  });
}
